package com.hellenic.dao;

import java.util.ArrayList;

import org.hibernate.Query;
//import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
//import org.hibernate.Transaction;

import com.hellenic.beans.ReservationBean;

public class ReservationDao implements ReservationDaoInt {
    private SessionFactory sessionF;

    public ReservationDao( SessionFactory sessionF ) {
        this.sessionF = sessionF;
        System.out.println( "Message : Instanciation d'un objet ReservationDao" );
    }



    /**
     * Permet la creation d'une reservation
     */
    @Override
    public boolean create( String nom, String prenom, String email, String telephone, String date,
            String pays ,String propriete )
            throws DaoException {
        String hql = "";
        System.out.println( "HQL : " + hql );
        Session sess = null;
        //TODO faire requette hql creation resa
        try {
            sess = sessionF.openSession();
            //Query query = sess.createQuery( hql );
            
        } catch ( DaoException e ) {
            System.out.println( "ERREUR : execution get() dans ProprieteDAO " );
        } finally {
            sess.close();
        }
        
        return false;
    }


    /**
     * Permet la récupération des reservations
     */
    @SuppressWarnings( "unchecked" )
    @Override
    public ArrayList<ReservationBean> getAll() throws DaoException {
        String hql = "FROM com.hellenic.beans.ReservationBean reservation";
        ArrayList<ReservationBean> list = null;
        System.out.println( "HQL : " + hql );

        try {
            // ouverture d'une session hibernate
            Session ses = sessionF.openSession();

            // ouverture de la transaction
            Transaction tx = ses.beginTransaction();

            // execute la requete
            Query query = ses.createQuery( hql );

            // met le resultat sous form de list
            list = (ArrayList<ReservationBean>) query.list();

            // fermeture transaction
            tx.commit();

            // libération des resources ????
            ses.close();
        } catch ( DaoException ex ) {
            System.out.println( "Erreur : execution dans ReservationDao" );
        }
        return list;
    }



    @Override
    public boolean delete( String id ) throws DaoException {
        // TODO Auto-generated method stub
        return false;
    }


}